<?php
	error_reporting(E_ALL || ~E_NOTICE);

	$delIds[] = $_POST['delIds'];
//	var_dump($delIds);
	$delArr[] = explode(",", $delIds[0]);
/*	$data=file_get_contents('php://input');
	if($data)
	{		
		$jsondata=json_decode($data,true);
	}
	$delArr[] = $jsondata['delIds'];*/
	$myconn=dwopendb();
	$i=0;
	foreach($delArr[0] as $ide)
	{ 
//		var_dump($delArr);
//		file_put_contents("test.log","ide: ".$ide." LINE:".__LINE__."\n", FILE_APPEND);
//		foreach($ide as $id)
//		{
			$exec="delete from gatesetting where skid=$ide AND controlernum!=\"ALL\";";
			$result=mysql_query($exec,$myconn); 
//			file_put_contents("test.log","exec: ".$exec." LINE:".__LINE__."\n", FILE_APPEND);
			if((mysql_affected_rows($myconn)==0) or (mysql_affected_rows($myconn)==-1)) 
			{ 
				echo '{"errorMsg":"没有找到记录，或者删除时出错"}';
	//			echo "<script language=\"JavaScript\">alert(\"没有找到记录，或者删除时出错\");</script><br/>"; 
		//				echo "<script language=\"JavaScript\">self.setTimeout(window.location.href='/door/adminsetting.php',5000);</script><br/>";
		//				exit;
				return; 
			} 
			else
			{ 			
				$i += 1;
		//		echo "<script language=\"JavaScript\">alert(\"序号 ".$ide." 已删除。\");</script><br/>"; 
		/*				echo "<script language=\"JavaScript\">alert('授权成功。');</script><br/>";
				echo "<script language=\"JavaScript\">alert('序号 ".$ide." 已删除。');</script><br/>"; 
				echo "<script language=\"JavaScript\">self.setTimeout(window.location.href='/door/adminsetting.php',5000);</script><br/>";
		*/
		//		echo '{"res":"fail"}';	
			}
			mysql_free_result($result);
//		}
	}	
	dwclosedb($myconn);
	echo '{"success":"true","delNums":"'.$i.'"}';
	return;

	function dwclosedb($myconn)
	{
		mysql_close($myconn);	
	}
	
	function dwopendb()
	{
		$myconn=@mysql_connect("localhost","dw","DWdawu-309");
		if(!$myconn)
		{
//			die('Could not connect: '.mysql_error());
			$string = "Can't connect database : ".mysql_error()." LINE:".__LINE__."\n";
			file_put_contents("test.log", $string, FILE_APPEND);
			echo '{"errorMsg":$string}';
			return false;
		}
		$db_selected=mysql_select_db("dwzuapairenlian",$myconn);
		if(!$db_selected)
		{
//			die("Can't use database dwaccessDB : ".mysql_error());       
			$strSql="CREATE DATABASE dwzuapairenlian;";
			$result=mysql_query($strSql,$myconn);
			if($result==false)
			{
				die("Can't use database dwaccessDB : ".mysql_error());
				$string = "Can't use database : ".mysql_error()." LINE:".__LINE__."\n";
				file_put_contents("test.log", $string, FILE_APPEND);
				dwclosedb($myconn);
//				$response = base64_encode("{\"res\":\"deny3\"}");
				echo '{"errorMsg":$string}';
//				echo $response;					
				return false;
			}
			$strSql="set character_set_database=utf8;";
			$result=mysql_query($strSql,$myconn);
	
			mysql_close($myconn);
			return false;
		}
		return $myconn;
	}	

?>	